package com.cedifie.lendapp.ui.user.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.cedifie.lendapp.R
import com.cedifie.lib_baseadapter.CEDRecyclerViewAdapter
import com.cedifie.lib_baseadapter.CEDViewHolderHelper
import org.json.JSONObject

/**
 * Cedifie
 * @Author wwdeng
 * @CreateTime: 2024/6/17 13:45
 * @Annotation：客服 - 联系方式列表
 */
class CedKefuContactAdapter(recyclerView: RecyclerView?): CEDRecyclerViewAdapter<JSONObject>(recyclerView,R.layout.item_kefu_contact) {

    override fun setItemChildListener(helper: CEDViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.btnCopy) //复制
        helper.setItemChildClickListener(R.id.btnDial)//拨号
    }

    override fun fillData(helper: CEDViewHolderHelper, position: Int, model: JSONObject) {
        helper.setText(R.id.textContent,model.optString("value"))
        val imgView = helper.getImageView(R.id.imgView)

        val type = model.optString("type")
        when(type){
            "MOBILE" -> {//电话
                imgView.setImageResource(R.mipmap.icon_kefu_contact_phone)
                helper.setText(R.id.textType,mContext.getString(R.string.kefu_contact_number))
                helper.setVisibility(R.id.btnDial, View.VISIBLE)
            }
            else -> {//邮箱
                imgView.setImageResource(R.mipmap.icon_kefu_contact_email)
                helper.setText(R.id.textType,mContext.getString(R.string.kefu_contact_email))
                helper.setVisibility(R.id.btnDial, View.GONE)
            }
        }

        if (position == itemCount - 1){
            helper.setVisibility(R.id.vLine, View.GONE)
        } else {
            helper.setVisibility(R.id.vLine, View.VISIBLE)
        }
    }
}